package com.sctvcloud.qingchuan.ui.dialog;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ruihang.generalibrary.ui.dialog.BaseBottomSheetFrag;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.IShares;
import com.sctvcloud.qingchuan.R;
import com.sctvcloud.qingchuan.beans.WarningItemBean;
import com.sctvcloud.qingchuan.ui.adapter.WarningAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * 融媒号举报页面
 */
public class AccountWarningFragment extends BaseBottomSheetFrag implements WarningAdapter.OnItemBtnClick {

    private IShares shares;
    private String shareType;

    private RecyclerView warningList;
    private CustomFontTextView submit;
    private List<WarningItemBean> list;
    private WarningAdapter adapter;
    private OnWarningConfirmListener confirmListener;
    private String selectedTitle;

    public AccountWarningFragment() {
    }

    public void setConfirmListener(OnWarningConfirmListener confirmListener) {
        this.confirmListener = confirmListener;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public int getLayoutResId() {
        return R.layout.dia_fragment_account_warning;
    }

    public void initView() {
        warningList = (RecyclerView) rootView.findViewById(R.id.warnig_list);
        warningList.setItemAnimator(new DefaultItemAnimator());
        warningList.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
        list = new ArrayList<>();
        list.add(new WarningItemBean("标题夸张", false));
        list.add(new WarningItemBean("低俗色情", false));
        list.add(new WarningItemBean("错别字多", false));
        list.add(new WarningItemBean("涉嫌违法犯罪", false));
        list.add(new WarningItemBean("其他问题，我要吐槽", true));
        list.get(0).setSelected(true);
        selectedTitle = list.get(0).getTitle();
        adapter = new WarningAdapter(getContext(), list, this);
        warningList.setAdapter(adapter);

        submit = (CustomFontTextView) rootView.findViewById(R.id.to_submit);
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AccountWarningFragment.this.dismissAllowingStateLoss();
                confirmListener.OnWarningConfirm(selectedTitle, false);
            }
        });

    }

    @Override
    public void onItemBtnClick(String title, int position, boolean isMore) {
        if (!isMore) {
            selectedTitle = title;
            list.get(position).setSelected(true);
            for (int i = 0; i < list.size(); i++) {
                if (i == position) {
                    list.get(i).setSelected(true);
                } else {
                    list.get(i).setSelected(false);
                }
            }
            adapter.setDataList(list);
        } else {
            confirmListener.OnWarningConfirm(title, isMore);
        }

    }

    public interface OnWarningConfirmListener {
        void OnWarningConfirm(String title, boolean isMore);
    }
}
